$("#xsdForm").submit(function(event){
	$.ajax({
		type: $(this).attr('method'),
		data: new FormData($(this).get(0)),
		url: $(this).attr('action'),
	    cache: false,
	    processData: false,
	    contentType: false,
	    success: function(data) {
	    	xsdDisplayer.setValue(data.xsdContent);
	    	//receivedXsd = data.xsdTree;
	    	// create the root node right after submission of xsd
	    	// new node created => increase counter to make a unique ID
	    	
	    	// get ROOT info
	    	// what root ID is
	    	var rootId = receivedXsd["rootElementId"];
	    	elementsList = receivedXsd["elements"];
	    	
	    	var root = elementsList[rootId];
	    	var branches = $("<li><div class='element-div complex-type unfinished' id='" + rootId + "'>" 
	    			+ rootId + "</div><ul></ul></li>").appendTo("#xml");
/*	         var branches =	$("<li><div class='element-div complex-type' id='" + rootId + "'>Item 1</div>" 
						+"<ul>" +
	    				"<li><div class='element-div complex-type'>Hello</div></li>" +
	    				"<li><div class='element-div complex-type'>Hello</div></li>" +
	    				"<li><div class='element-div complex-type'>Hello</div></li>" +
	    				"<li><div >Hello</div></li>" +
	    			"</ul></li>").appendTo("#xml");
*/	    		$("#xml").treeview({
	    			add: branches
	    	});
	    },
	    error: function(xhr, err, status){
	    	setMessage(err);
	    }
	});
	return false;
});

function setMessage(msg){
	$("#error-message").html(msg);
}
